package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TemplateFieldData;
import com.ruoyi.system.service.ITemplateFieldDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务模板字段Controller
 * 
 * @author chenming
 * @date 2024-10-16
 */
@RestController
@RequestMapping("/system/templateFieldData")
public class TemplateFieldDataController extends BaseController
{
    @Autowired
    private ITemplateFieldDataService templateFieldDataService;

    /**
     * 查询业务模板字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:templateFieldData:list')")
    @GetMapping("/list")
    public TableDataInfo list(TemplateFieldData templateFieldData)
    {
        startPage();
        List<TemplateFieldData> list = templateFieldDataService.selectTemplateFieldDataList(templateFieldData);
        return getDataTable(list);
    }

    /**
     * 导出业务模板字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:templateFieldData:export')")
    @Log(title = "业务模板字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TemplateFieldData templateFieldData)
    {
        List<TemplateFieldData> list = templateFieldDataService.selectTemplateFieldDataList(templateFieldData);
        ExcelUtil<TemplateFieldData> util = new ExcelUtil<TemplateFieldData>(TemplateFieldData.class);
        util.exportExcel(response, list, "业务模板字段数据");
    }

    /**
     * 获取业务模板字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:templateFieldData:query')")
    @GetMapping(value = "/{fieldId}")
    public AjaxResult getInfo(@PathVariable("fieldId") Long fieldId)
    {
        return success(templateFieldDataService.selectTemplateFieldDataByFieldId(fieldId));
    }

    /**
     * 新增业务模板字段
     */
    @PreAuthorize("@ss.hasPermi('system:templateFieldData:add')")
    @Log(title = "业务模板字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TemplateFieldData templateFieldData)
    {
        return toAjax(templateFieldDataService.insertTemplateFieldData(templateFieldData));
    }

    /**
     * 修改业务模板字段
     */
    @PreAuthorize("@ss.hasPermi('system:templateFieldData:edit')")
    @Log(title = "业务模板字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TemplateFieldData templateFieldData)
    {
        return toAjax(templateFieldDataService.updateTemplateFieldData(templateFieldData));
    }

    /**
     * 删除业务模板字段
     */
    @PreAuthorize("@ss.hasPermi('system:templateFieldData:remove')")
    @Log(title = "业务模板字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fieldIds}")
    public AjaxResult remove(@PathVariable Long[] fieldIds)
    {
        return toAjax(templateFieldDataService.deleteTemplateFieldDataByFieldIds(fieldIds));
    }
}
